﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using BaseEntities;

namespace Mock1Group6
{
    public partial class Withdraw : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button7.Visible = true;
            Button8.Visible = true;
            Button9.Visible = true;
            Button10.Visible = true;
            Button11.Visible = true;
            Button12.Visible = true;
            Label1.Visible = false;
            txtenteramount.Visible = false;
        }
        void widthDraw(decimal amount)
        {
            Card card = new Card();
            card.CardNo = Session["CardNo"].ToString();
            //card.CardNo = "1111111111111111";
            Account account = new Account();
            Session["AccountID"] = BusinessLogic.WithdrawLogic.returnAccountID(card);
            //Session["AccountID"] = "1";
            account.AccountID = Int32.Parse(Session["AccountID"].ToString());
            ATM atm = new ATM();
            Session["ATMID"] = "1";
            atm.ATMID = Int32.Parse(Session["ATMID"].ToString());
            // Response.Write(BusinessLogic.WithdrawLogic.getBalance(card));
            // grView.DataSource = BusinessLogic.WithdrawLogic.getBalance1(card);
            //grView.DataBind();
            if (WithdrawLogic.CheckWithdrawCash(amount, card) == false)
            {
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('So tien trong tai khoan khong du de thuc hien giao dich');", true);
                Button7.Visible = false;
                Button8.Visible = false;
                Button9.Visible = false;
                Button10.Visible = true;
                Button11.Visible = false;
                Button12.Visible = false;
                Label1.Visible = true;
                Label1.Text = "So tien trong tai khoan khong du de thuc hien giao dich";
                Button10.Text = "OK";
                Session["ok"] = "ok";
            }
            else
                if (WithdrawLogic.CheckCashWithMinMaxValue(amount, card) == false)
                {
                    // Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('So tien trong tai khoan khong thoa man dieu kien');", true);
                    Button7.Visible = false;
                    Button8.Visible = false;
                    Button9.Visible = false;
                    Button10.Visible = true;
                    Button11.Visible = false;
                    Button12.Visible = false;
                    Label1.Visible = true;
                    Label1.Text = "So tien trong tai khoan khong thoa man dieu kien";
                    Button10.Text = "OK";
                    Session["ok"] = "ok";
                }
                else
                    if (WithdrawLogic.CheckCashWithMod(amount, card) == false)
                    {
                        //Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('So tien rut phai chia het cho 50000');", true);
                        Button7.Visible = false;
                        Button8.Visible = false;
                        Button9.Visible = false;
                        Button10.Visible = true;
                        Button11.Visible = false;
                        Button12.Visible = false;
                        Label1.Visible = true;
                        Label1.Text = "So tien rut phai chia het cho 50000";
                        Button10.Text = "OK";
                        Session["ok"] = "ok";
                    }
                    else
                        if (amount > WithdrawLogic.GetAllMoney())
                        {
                            // Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('So tien hien co trong cay khong du thuc hien giao dich');", true);
                            Button7.Visible = false;
                            Button8.Visible = false;
                            Button9.Visible = false;
                            Button10.Visible = true; ;
                            Button11.Visible = false;
                            Button12.Visible = false;
                            Label1.Visible = true;
                            Label1.Text = "So tien hien co trong cay khong du thuc hien giao dich";
                            Button10.Text = "OK";

                            Session["ok"] = "ok";
                        }
                        else
                            if ((WithdrawLogic.CheckWithdrawCash(amount, card) == true) &&
                            (WithdrawLogic.CheckCashWithMinMaxValue(amount, card) == true) &&
                            (WithdrawLogic.CheckCashWithMod(amount, card) == true) &&
                             (amount <= WithdrawLogic.GetAllMoney()))
                            {
                                Button7.Visible = false;
                                Button8.Visible = false;
                                Button9.Visible = false;
                                Button10.Visible = true;
                                Button11.Visible = false;
                                Button12.Visible = false;
                                Label1.Visible = true;
                                Label1.Text = "Rut tien thanh cong.ban co muon in hoa don";
                                Button10.Text = "OK";
                                Button12.Visible = false;
                                WithdrawLogic.UpdateBalance(amount, card, account);
                                WithdrawLogic.WriteLog(atm, card, amount);
                                Session["inhoadon"]="inhoadon";
                            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            widthDraw(500000);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            widthDraw(2000000);
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            widthDraw(3000000);
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            widthDraw(1000000);
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            if (Session["inhoadon"] != null)
            {
                Response.Redirect("FormMain.aspx");
            }
            if (Session["ok"] != null)
            {
                Button7.Visible = true;
                Button8.Visible = true;
                Button9.Visible = true;
                Button10.Visible = true;
                Button10.Text = "2500000";
                Button11.Visible = true;
                Button12.Visible = true;
                Label1.Visible = false;
            }
            if (Session["Enterother"]!=null)
            {
                widthDraw(decimal.Parse(txtenteramount.Text));
            }
            else
            {
                widthDraw(2500000);
            }
        }


        protected void Button6_Click(object sender, EventArgs e)
        {
            Response.Redirect("Withdraw2.aspx");
            /*Session["Enterother"] = "Enterother";
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";*/
        }

        protected void Button7_Click(object sender, EventArgs e)
        {

        }

        protected void Button8_Click(object sender, EventArgs e)
        {

        }

        protected void Button11_Click(object sender, EventArgs e)
        {

        }

        protected void Button9_Click(object sender, EventArgs e)
        {

        }

        protected void Button10_Click(object sender, EventArgs e)
        {

        }

        protected void Button12_Click(object sender, EventArgs e)
        {

        }
        protected void btn1_Click(object sender, EventArgs e)
        {
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";
            txtenteramount.Text = txtenteramount.Text + "1";
        }

        protected void btn2_Click(object sender, EventArgs e)
        {
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";
            txtenteramount.Text = txtenteramount.Text + "2";
        }

        protected void btn3_Click(object sender, EventArgs e)
        {
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";
            txtenteramount.Text = txtenteramount.Text + "3";
        }

        protected void btn4_Click(object sender, EventArgs e)
        {
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";
            txtenteramount.Text = txtenteramount.Text + "4";
        }

        protected void btn5_Click(object sender, EventArgs e)
        {
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";
            txtenteramount.Text = txtenteramount.Text + "5";
        }

        protected void btn6_Click(object sender, EventArgs e)
        {
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";
            txtenteramount.Text = txtenteramount.Text + "6";
        }

        protected void btn7_Click(object sender, EventArgs e)
        {
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";
            txtenteramount.Text = txtenteramount.Text + "7";
        }

        protected void btn8_Click(object sender, EventArgs e)
        {
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";
            txtenteramount.Text = txtenteramount.Text + "8";
        }

        protected void btn9_Click(object sender, EventArgs e)
        {
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";
            txtenteramount.Text = txtenteramount.Text + "9";
        }

        protected void btn0_Click(object sender, EventArgs e)
        {
            lb1.InnerText = "Enter your amount you want to withdraw below";
            lb2.InnerText = "number you enter have to divisible to 50.000";
            txtenteramount.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = false;
            Button11.Visible = false;
            Button10.Text = "Ok";
            Button12.Text = "Cancel";
            txtenteramount.Text = txtenteramount.Text + "0";
        }

        protected void btnCham_Click(object sender, EventArgs e)
        {
            txtenteramount.Text = txtenteramount.Text + ".";
        }
        protected void btnEnter_Click(object sender, EventArgs e)
        {
            widthDraw(decimal.Parse(txtenteramount.Text));
        }
        protected void btnRong_Click(object sender, EventArgs e)
        {
            txtenteramount.Text = txtenteramount.Text + "";
        }
 }
    }
